<?php
/**
 * Created by PhpStorm.
 * User: 宋春宝
 * Date: 2018/11/14
 * Time: 8:39
 */

namespace app\admin\controller;


class Test
{
    private function dis(){
        //236
        db('dispatch')->where('id','>=',201)->where('id','<=',236)->chunk(10,function ($all){
            foreach ($all as $v){
                $step = db('dispatch_flow')->where('dispatch_id',$v['id'])->count();
                if($step>0){
                    $info = db('dispatch_flow')->where('dispatch_id',$v['id'])->order('step','desc')->find();
                    $input = [
                        'dispatch_id'=>$v['id'],
                        'title'=>$v['title'],
                        'admin_id'=>$info['admin_id'],
                        'step'=>$info['step'],
                        'add_time'=>date('Y-m-d H:i:s'),
                        'update_time'=>date('Y-m-d H:i:s')
                    ];
                    if($info['step']==9){
                        $input['is_comp'] = 1;
                    }

                    $id = db('dispatch_sheets')->insertGetId($input);

                    $fl = [
                        'sheet_id'=>$id
                    ];
                    db('dispatch_flow')->where('dispatch_id',$v['id'])->update($fl);

                    $f6 = db('dispatch_flow')->where('dispatch_id',$v['id'])->where('step',6)->find();
                    if($f6){
                        db('dispatch_flow')->where('dispatch_id',$v['id'])->where('step',6)->update(['attach'=>$v['ticket'].';'.$v['guard']]);
                    }

                    $f9 = db('dispatch_flow')->where('dispatch_id',$v['id'])->where('step',9)->find();
                    if($f9){
                        db('dispatch_flow')->where('dispatch_id',$v['id'])->where('step',9)->update(['attach'=>$v['arga']]);
                    }
                }
            }
        });

        return 'success230';
    }

    public function disd(){
        db('dispatch')->where('id','<=',236)->update(['']);
    }
}